package com.javabean;


import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import com.model.DataBase;

public class SelectData {
	Connection con = DataBase.getConnection();
	PreparedStatement pre;
	ArrayList a=new ArrayList();
	ResultSet rs;
	
	public ArrayList find(String type,String keyword ){
		//System.out.println("开始");
		if(type.equals("设备名称")){
			String sql="select * from device where type = ?";
			try {
				pre=con.prepareStatement(sql);
				pre.setString(1, "%"+keyword+"%");
				rs=pre.executeQuery();
				while(rs.next()){
					a.add(rs.getLong(1));
					a.add(rs.getString(2));
					a.add(rs.getInt(3));
					a.add(rs.getString(4));
					a.add(rs.getString(8));
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		else if(type.equals("设备编号")){
			String sql="select * from device where serial = ?";
			try {
				pre=con.prepareStatement(sql);
				pre.setString(1,"%"+keyword+"%");
				rs=pre.executeQuery();
				while(rs.next()){
					a.add(rs.getLong(1));
					a.add(rs.getString(2));
					a.add(rs.getInt(3));
					a.add(rs.getString(4));
					a.add(rs.getString(8));
				}
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return a;
		
	}
}
